<template>
  <el-dialog :visible="isShow" :destroy-on-close="true" @close="closeModal">
    <el-form label-suffix=":">
      <el-form-item label="接收用户">
        <el-select v-model="user">
          <el-option value="test1" label="test1" />
          <el-option value="test2" label="test2" />
          <el-option value="test3" label="test3" />
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer">
      <el-button @click="closeModal">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save">保存并发送</el-button>
    </span>
  </el-dialog>

</template>

<script>
import { helper } from '@/utils/T';
import { SendFlow, SaveFormData } from '@/api/formManagement';
import EnumRouter from '@/constants/EnumRouter';
export default {
  name: 'SendFlowModal',
  props: {
    isShow: {
      type: Boolean,
      required: true,
      default: false
    },
    formData: {
      type: Object,
      required: true,
      default: () => ({})
    },
    formId: {
      type: Number,
      required: true,
      default: null
    }
  },
  data() {
    return {
      user: 'test1',
      loading: false
    };
  },
  mounted() {
    // console.log(helper.getUrlParams());
  },
  methods: {
    closeModal() {
      this.$emit('update:isShow', false);
    },
    save() {
      const { workId, user } = helper.getUrlParams();
      SaveFormData({ workId, formId: this.formId, data: this.formData }).then(res => {
        return SendFlow({ userNo: user, sysNo: '1001', toEmps: this.user, workId });
      }, err => {
        this.loading = false;
        this.$message.error(err.msg);
      }).then(res => {
        this.loading = false;
        this.$message.success(res.message);
        this.$router.push(EnumRouter.todoList);
        this.closeModal();
      }, err => {
        this.loading = false;
        this.$message.error(err.message);
      });
    }
  }
};
</script>

<style scoped>

</style>
